//
//  KRAlartManager.m
//  KEREN
//
//  Created by MW on 2023/3/15.
//

#import "KRAlartManager.h"
#import "PickViewAlartView.h"

@implementation KRAlartManager
+ (instancetype)shareInstance {
    
    static KRAlartManager *manager;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        manager = [[self alloc]init];
    });
    return manager;
}

- (void)resettingDeteRow{
    self.dayRow = 0;
    self.yearRow = 0;
    self.monthRow = 0;
}

-(void)showBLENotOpenAlert{
    UIWindow *window = UIApplication.sharedApplication.delegate.window;
    [window addSubview:self.backView];
    UIView *whiteView = [[UIView alloc] initWithFrame:CGRectMake(0, DEVICE_HEIGHT, DEVICE_WIDTH, 487)];
    whiteView.backgroundColor = [UIColor whiteColor];
    whiteView.layer.mask = [CAShapeLayer clipsToBounds:whiteView.bounds Corners:UIRectCornerTopLeft | UIRectCornerTopRight cornerRadii:CGSizeMake(25, 25)];
    [_backView addSubview:whiteView];
    [UIView setLineViewWithframe:CGRectMake(0, 57, DEVICE_WIDTH, 1) forinView:whiteView];
    [UIView animateWithDuration:0.5 animations:^{
        whiteView.frame = CGRectMake(0, DEVICE_HEIGHT - 360, DEVICE_WIDTH, 360);
    }];
    
    UIButton *closeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [whiteView addSubview:closeBtn];
    [closeBtn setImage:[UIImage imageNamed:@"NavBar_Default_Close"] forState:UIControlStateNormal];
    [closeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.offset(-10);
        make.width.height.offset(40);
        make.top.offset(10);
    }];
    [closeBtn addTarget:self action:@selector(hidenAlartView) forControlEvents:UIControlEventTouchUpInside];
    UIImageView *imageView = [[UIImageView alloc] init];
    [whiteView addSubview:imageView];
    [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(_backView);
        make.height.width.offset(176);
        make.top.offset(78);
    }];
    imageView.image = [UIImage imageNamed:@"devce_band_noBLE"];
    UILabel *textLbl = [UILabel setLblText:@"当前蓝牙未打开" font:Font(16) withColor:Color_333333 inSubView:whiteView];
    [textLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(_backView);
        make.top.equalTo(imageView.mas_bottom).offset(0);
    }];
}

-(void)showBLENotFoundDeviceAlert{
    UIWindow *window = UIApplication.sharedApplication.delegate.window;
    [window addSubview:self.backView];
    UIView *whiteView = [[UIView alloc] initWithFrame:CGRectMake(0, DEVICE_HEIGHT, DEVICE_WIDTH, 487)];
    whiteView.backgroundColor = [UIColor whiteColor];
    whiteView.layer.mask = [CAShapeLayer clipsToBounds:whiteView.bounds Corners:UIRectCornerTopLeft | UIRectCornerTopRight cornerRadii:CGSizeMake(25, 25)];
    [_backView addSubview:whiteView];
    [UIView setLineViewWithframe:CGRectMake(0, 57, DEVICE_WIDTH, 1) forinView:whiteView];
    [UIView animateWithDuration:0.5 animations:^{
        whiteView.frame = CGRectMake(0, DEVICE_HEIGHT - 380, DEVICE_WIDTH, 380);
    }];
    
    UIButton *closeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [whiteView addSubview:closeBtn];
    [closeBtn setImage:[UIImage imageNamed:@"NavBar_Default_Close"] forState:UIControlStateNormal];
    [closeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.offset(-10);
        make.width.height.offset(40);
        make.top.offset(10);
    }];
    [closeBtn addTarget:self action:@selector(hidenAlartView) forControlEvents:UIControlEventTouchUpInside];
    UIImageView *imageView = [[UIImageView alloc] init];
    [whiteView addSubview:imageView];
    [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(_backView);
        make.height.width.offset(176);
        make.top.offset(78);
    }];
    imageView.image = [UIImage imageNamed:@"share_nouser"];
    UILabel *textLbl = [UILabel setLblText:@"1、未发现想要的设备，可尝试重新扫描\n2、检查当前环境信号强度，并尝试靠近蓝牙设备" font:Font(16) withColor:Color_333333 inSubView:whiteView];
    textLbl.numberOfLines = 0;
    [textLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(_backView);
        make.top.equalTo(imageView.mas_bottom).offset(0);
        make.left.offset(16);
        make.right.offset(-16);
    }];
    //imageView
}

- (void)showNavigationView{
    
}

- (void)showTipsAlertWithTitle:(NSString *)title decTitle:(NSString *)dec cancleBtnText:(NSString *)cancletStr andOkBtnText:(NSString *)okStr sucessBlock:(sucessBlock)sucessBlock{
    _sucessBlock = sucessBlock;
    UIWindow *window = UIApplication.sharedApplication.delegate.window;
    [window addSubview:self.backView];
    UIView *whiteView = [[UIView alloc] init];
    [_backView addSubview:whiteView];
    UILabel *titleLbl = [[UILabel alloc] init];
    [whiteView addSubview:titleLbl];
    [titleLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(24);
        make.left.offset(24);
        make.width.offset(DEVICE_WIDTH-48);
    }];
    titleLbl.textColor = Black_Color;
    titleLbl.font = Font_Medium(20);
    titleLbl.text = title;
    titleLbl.textAlignment = NSTextAlignmentCenter;
    
    UILabel *decLbl = [[UILabel alloc] init];
    [whiteView addSubview:decLbl];
    [decLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(24);
        make.right.offset(-24);
        make.top.equalTo(titleLbl.mas_bottom).offset(8);
    }];
    decLbl.font = Font(14);
    decLbl.textColor = Black_Color;
    decLbl.numberOfLines = 0;
    decLbl.text = dec;
    decLbl.textAlignment = NSTextAlignmentCenter;
    UIView *lineView = [[UIView alloc] init];
    [whiteView addSubview:lineView];
    [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(decLbl.mas_bottom).offset(24);
        make.height.offset(1);
        make.left.right.offset(0);
    }];
    lineView.backgroundColor = rgba(0, 0, 0, 0.12);
    
    UIView *vLineView = [[UIView alloc] init];
    [whiteView addSubview:vLineView];
    [vLineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(whiteView);
        make.width.offset(1);
        make.height.offset(48 + 16);
        make.top.equalTo(decLbl.mas_bottom).offset(25);
    }];
    vLineView.backgroundColor = rgba(0, 0, 0, 0.12);

    UIButton *cancleBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [whiteView addSubview:cancleBtn];
    [cancleBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(0);
        make.height.offset(48);
        make.right.equalTo(vLineView.mas_left).offset(0);
        make.top.equalTo(lineView.mas_bottom).offset(0);
    }];
    [cancleBtn setTitle:@"取消" forState:UIControlStateNormal];
    [cancleBtn setTitleColor:Black_Color forState:UIControlStateNormal];
    cancleBtn.titleLabel.font = Font_Medium(16);
    [cancleBtn addTarget:self action:@selector(cancleBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    
    UIButton *okBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [whiteView addSubview:okBtn];
    [okBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.offset(0);
        make.height.offset(48);
        make.left.equalTo(vLineView.mas_right).offset(0);
        make.top.equalTo(lineView.mas_bottom).offset(0);
    }];
    [okBtn setTitle:@"确认" forState:UIControlStateNormal];
    [okBtn setTitleColor:Color_7ACC00 forState:UIControlStateNormal];
    okBtn.titleLabel.font = BFont(16);
    [okBtn addTarget:self action:@selector(senderClick:) forControlEvents:UIControlEventTouchUpInside];
    [whiteView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(0);
        make.right.offset(0);
        make.bottom.offset(0);
        make.bottom.equalTo(okBtn.mas_bottom).offset(16);
    }];
    whiteView.backgroundColor = Color_FAFAFA;
    [whiteView setNeedsLayout];
    [whiteView layoutIfNeeded];
    whiteView.layer.mask = [CAShapeLayer clipsToBounds:whiteView.bounds Corners:UIRectCornerTopLeft | UIRectCornerTopRight cornerRadii:CGSizeMake(25, 25)];
}

- (void)showTipsAlertWithTitle:(NSString *)title decTitle:(NSString *)dec andOkBtnText:(NSString *)okStr sucessBlock:(sucessBlock)sucessBlock{
    _sucessBlock = sucessBlock;

    UIWindow *window = UIApplication.sharedApplication.delegate.window;
    [window addSubview:self.backView];
    UIView *whiteView = [[UIView alloc] init];
    [_backView addSubview:whiteView];
    UILabel *titleLbl = [[UILabel alloc] init];
    [whiteView addSubview:titleLbl];
    [titleLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(24);
        make.left.offset(24);
        make.width.offset(DEVICE_WIDTH-48);
    }];
    titleLbl.textColor = Black_Color;
    titleLbl.font = Font_Medium(20);
    titleLbl.text = title;
    titleLbl.textAlignment = NSTextAlignmentCenter;
    
    UILabel *decLbl = [[UILabel alloc] init];
    [whiteView addSubview:decLbl];
    [decLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(24);
        make.right.offset(-24);
        make.top.equalTo(titleLbl.mas_bottom).offset(8);
    }];
    decLbl.font = Font(14);
    decLbl.textColor = Black_Color;
    decLbl.numberOfLines = 0;
    decLbl.text = dec;
    
    UIView *lineView = [[UIView alloc] init];
    [whiteView addSubview:lineView];
    [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(decLbl.mas_bottom).offset(24);
        make.height.offset(1);
        make.left.right.offset(0);
    }];
    lineView.backgroundColor = rgba(0, 0, 0, 0.12);

    UIButton *okBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [whiteView addSubview:okBtn];
    [okBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.offset(0);
        make.height.offset(48);
        make.left.offset(0);
        make.top.equalTo(lineView.mas_bottom).offset(0);
    }];
    [okBtn setTitle:@"确认" forState:UIControlStateNormal];
    [okBtn setTitleColor:Color_7ACC00 forState:UIControlStateNormal];
    okBtn.titleLabel.font = BFont(16);
    [okBtn addTarget:self action:@selector(senderClick:) forControlEvents:UIControlEventTouchUpInside];
    [whiteView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(0);
        make.right.offset(0);
        make.bottom.offset(0);
        make.bottom.equalTo(okBtn.mas_bottom).offset(16);
    }];
    whiteView.backgroundColor = Color_FAFAFA;
    [whiteView setNeedsLayout];
    [whiteView layoutIfNeeded];
    whiteView.layer.mask = [CAShapeLayer clipsToBounds:whiteView.bounds Corners:UIRectCornerTopLeft | UIRectCornerTopRight cornerRadii:CGSizeMake(25, 25)];
}

- (void)cancleBtnClick:(UIButton *)btn{
    btn.enabled = NO;
    _sucessBlock(NO);
    [self hidenAlartView];
}

- (void)senderClick:(UIButton *)btn{
    btn.enabled = NO;
    _sucessBlock(YES);
    [self hidenAlartView];
}

- (void)showAlert:(NSString *)title{
    WEAKSELF
    if(_errorView){
        [_errorView removeAllSubviews];
        [_errorView removeFromSuperview];
    }
    UIWindow *window = UIApplication.sharedApplication.delegate.window;
    [window addSubview:self.errorView];
    _errorView.layer.cornerRadius = 25;
    _errorView.clipsToBounds = YES;

    UILabel *errorLbl = [[UILabel alloc] init];
    [_errorView addSubview:errorLbl];
    errorLbl.text = title;
    errorLbl.textAlignment = NSTextAlignmentCenter;
    errorLbl.numberOfLines = 0;
    errorLbl.font = Font(14);
    errorLbl.textColor = rgba(1, 1, 1, 0.9);
    [_errorView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(errorLbl.mas_bottom).offset(16);
        make.width.mas_lessThanOrEqualTo(DEVICE_WIDTH - 48 - 40);
        make.centerY.centerX.equalTo(window);
    }];
    [errorLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(_errorView);
        make.left.offset(20);
        make.right.offset(-20);
        make.top.offset(16);
    }];
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        if(weakSelf.errorView){
            [weakSelf.errorView removeAllSubviews];
            [weakSelf.errorView removeFromSuperview];
        }
    });
}

- (void)showErrorAlert:(NSString *)errorStr{
    WEAKSELF
    if(_errorView){
        [_errorView removeAllSubviews];
        [_errorView removeFromSuperview];
    }
    UIWindow *window = UIApplication.sharedApplication.delegate.window;
    [window addSubview:self.errorView];
    UIImageView *errorIcon = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"error_icon"]];
    [_errorView addSubview:errorIcon];
    [errorIcon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(16);
        make.centerX.equalTo(_errorView);
        make.width.height.offset(36);
    }];
    _errorView.layer.cornerRadius = 25;
    _errorView.clipsToBounds = YES;
    UILabel *errorLbl = [[UILabel alloc] init];
    [_errorView addSubview:errorLbl];
    errorLbl.text = errorStr;
    errorLbl.textAlignment = NSTextAlignmentCenter;
    errorLbl.numberOfLines = 0;
    errorLbl.font = Font(14);
    errorLbl.textColor = rgba(1, 1, 1, 0.9);
    [_errorView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(errorLbl.mas_bottom).offset(16);
        make.width.mas_lessThanOrEqualTo(DEVICE_WIDTH - 48 - 40);
        make.centerY.centerX.equalTo(window);
    }];
    [errorLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(_errorView);
        make.left.offset(20);
        make.right.offset(-20);
        make.top.equalTo(errorIcon.mas_bottom).offset(6);
    }];
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        if(weakSelf.errorView){
            [weakSelf.errorView removeAllSubviews];
            [weakSelf.errorView removeFromSuperview];
        }
    });

}

- (void)showBleNotopenAlert{
    UIWindow *window = UIApplication.sharedApplication.delegate.window;
    [window addSubview:self.backView];
}

- (UIView *)showMessgeNoticeView{
    UIView *messageView = [[UIView alloc] init];
    messageView.backgroundColor = Color_7ACC00;
    UIImageView *icon = [[UIImageView alloc] initWithFrame:CGRectMake(24, 10, 20, 20)];
    [messageView addSubview:icon];
    icon.image = [UIImage imageNamed:@"notice_white_icon"];
    UILabel *messgeLbl = [[UILabel alloc] initWithFrame:CGRectMake(52, 10, DEVICE_WIDTH - 76, 20)];
    messgeLbl.text = @"你有待接收车辆分享的提醒，请查看";
    messgeLbl.textColor = Whire_Color;
    messgeLbl.font = BFont(14);
    //messgeLbl.textAlignment = 
    messageView.userInteractionEnabled = YES;
    messgeLbl.userInteractionEnabled = YES;
    [messageView addSubview:messgeLbl];
    NSMutableAttributedString *attritu = [[NSMutableAttributedString alloc]initWithString:messgeLbl.text];
    [attritu addAttributes:@{NSUnderlineStyleAttributeName: [NSNumber numberWithInteger:NSUnderlineStyleSingle]} range:NSMakeRange(messgeLbl.text.length - 3, 3)];
    messgeLbl.attributedText = attritu;

    return messageView;
}
- (void)showImageAlert:(NSString *)successStr ishaveBtn:(BOOL)ishaveBtn btnTitle:(NSString *)btnStr decLbl:(NSString *)dec withImageStr:(NSString *)imageStr isDown:(BOOL)isDown WithDownCount:(int)downCount sucessBlock:(sucessBlock)sucessBlock{
    _sucessBlock = sucessBlock;
    
    UIWindow *window = UIApplication.sharedApplication.delegate.window;
    [window addSubview:self.backView];
    UIView *whiteView = [[UIView alloc] init];
    whiteView.backgroundColor = Whire_Color;
    [self.backView addSubview:whiteView];
    
    UIButton *closeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [whiteView addSubview:closeBtn];
    [closeBtn setImage:[UIImage imageNamed:@"NavBar_Default_Close"] forState:UIControlStateNormal];
    [closeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.offset(-10);
        make.width.height.offset(40);
        make.top.offset(10);
    }];
    UIView *lineView = [UIView setLineViewWithframe:CGRectZero forinView:whiteView];
    [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(59);
        make.height.offset(1);
        make.left.right.offset(0);
    }];
    UIImageView *imageView = [[UIImageView alloc] init];
    [whiteView addSubview:imageView];
    [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(60);
        make.width.height.offset(180);
        make.centerX.equalTo(self.backView);
    }];
    imageView.image = [UIImage imageNamed:imageStr];
    UILabel *successLbl = [[UILabel alloc] init];
    successLbl.font = Font_Medium(20);
    successLbl.textColor = Black_Color;
    UILabel *decLbl = [[UILabel alloc] init];
    decLbl.text = dec;
    decLbl.font = Font(16);
    if(successStr.length > 0){
        successLbl.text = successStr;
        [whiteView addSubview:successLbl];
        [successLbl mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(imageView.mas_bottom).offset(0);
            make.centerX.equalTo(self.backView);
        }];
        [whiteView addSubview:decLbl];
        [decLbl mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(successLbl.mas_bottom).offset(4);
            make.centerX.equalTo(self.backView);
        }];
    }else{
        [whiteView addSubview:decLbl];
        [decLbl mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(imageView.mas_bottom).offset(0);
            make.centerX.equalTo(self.backView);
        }];
    }
    if(ishaveBtn){
        UIButton *btn = [UIButton setButtonWithTitle:btnStr titleColor:Whire_Color titleFont:BFont(16) cornerRadius:25 backColor:Color_7ACC00];
        [whiteView addSubview:btn];
        [btn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.equalTo(decLbl.mas_bottom).offset(24);
            make.left.offset(24);
            make.right.offset(-24);
            make.height.offset(58);
        }];
        [whiteView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.left.right.offset(0);
            make.bottom.equalTo(btn.mas_bottom).offset(BottomSpance_height);
        }];
    }else{
        [whiteView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.left.right.offset(0);
            make.bottom.equalTo(decLbl.mas_bottom).offset(BottomSpance_height);
        }];
    }
    [whiteView setNeedsLayout];
    [whiteView layoutIfNeeded];
    whiteView.layer.mask = [CAShapeLayer clipsToBounds:whiteView.bounds Corners:UIRectCornerTopLeft | UIRectCornerTopRight cornerRadii:CGSizeMake(25, 25)];
    if(isDown){
        _downCont = downCount;
        [self down:decLbl];
    }
    [closeBtn addTarget:self action:@selector(closeTimeDown) forControlEvents:UIControlEventTouchUpInside];

}

- (void)closeTimeDown{
    [self hidenAlartView];
    self.sucessBlock(NO);
}

- (void)showPickAlertView:(NSString *)title withcurrentIndex:(int)currentIndex IscanChooseHistory:(BOOL)iscanChooseHistory changeTitleBlock:(changeTitleBlock)changeTitleBlock{
    //402
    PickViewAlartView *pickView;
    if([title isEqualToString:@"蓝牙强度"]){
        pickView = [[PickViewAlartView alloc] initWithFrame:CGRectMake(0, DEVICE_HEIGHT - 325 - BottomSpance_height, DEVICE_WIDTH, 325 + BottomSpance_height) title:title currentIndex:currentIndex IsCanChooseHistory:iscanChooseHistory];
    }else if ([title isEqualToString:@"失窃上报类型"]){
        pickView = [[PickViewAlartView alloc] initWithFrame:CGRectMake(0, DEVICE_HEIGHT - 325 - BottomSpance_height, DEVICE_WIDTH, 325 + BottomSpance_height) title:title currentIndex:currentIndex IsCanChooseHistory:iscanChooseHistory];
    }
    else if ([title containsString:@"低电量设置"]){
        pickView = [[PickViewAlartView alloc] initWithFrame:CGRectMake(0, DEVICE_HEIGHT - 400 - BottomSpance_height, DEVICE_WIDTH, 400 + BottomSpance_height) title:title currentIndex:currentIndex IsCanChooseHistory:iscanChooseHistory];
    }else if([title containsString:@"离车自动锁定倒计时"]){
        pickView = [[PickViewAlartView alloc] initWithFrame:CGRectMake(0, DEVICE_HEIGHT - 325 - BottomSpance_height, DEVICE_WIDTH, 325 + BottomSpance_height) title:title currentIndex:currentIndex IsCanChooseHistory:iscanChooseHistory];
    }else if([title containsString:@"选择日期"]){
        pickView = [[PickViewAlartView alloc] initWithFrame:CGRectMake(0, DEVICE_HEIGHT - 400 - BottomSpance_height, DEVICE_WIDTH, 400 + BottomSpance_height) title:title currentIndex:currentIndex IsCanChooseHistory:iscanChooseHistory];
    }else if([title containsString:@"围栏半径"]){
        pickView = [[PickViewAlartView alloc] initWithFrame:CGRectMake(0, DEVICE_HEIGHT - 400 - BottomSpance_height, DEVICE_WIDTH, 400 + BottomSpance_height) title:title currentIndex:currentIndex IsCanChooseHistory:iscanChooseHistory];
    }
    
    UIWindow *window = UIApplication.sharedApplication.delegate.window;
    [window addSubview:self.backView];
    UIView *whiteView = [[UIView alloc] init];
    whiteView.backgroundColor = Whire_Color;
    [self.backView addSubview:pickView];
    pickView.changeTitleBlock = ^(NSString * _Nonnull title) {
        [self hidenAlartView];
        if(title.length > 0){
            changeTitleBlock(title);
        }else{
           // changeTitleBlock(@"");
        }
    };
}

- (void)showPointNavcation:(CGFloat)longitude latitude:(CGFloat)latitude pointName:(NSString *)pointName{
    //_location = location;
    _longitude = longitude;
    _latitude = latitude;
    _pointName = pointName;
    UIWindow *window = UIApplication.sharedApplication.delegate.window;
    [window addSubview:self.backView];
    UIView *whiteView = [[UIView alloc] initWithFrame:CGRectMake(0, DEVICE_HEIGHT - 178 - BottomSpance_height, DEVICE_WIDTH, 178 + BottomSpance_height)];
    whiteView.backgroundColor = Whire_Color;
    [self.backView addSubview:whiteView];
    whiteView.backgroundColor = [UIColor whiteColor];
    whiteView.layer.mask = [CAShapeLayer clipsToBounds:whiteView.bounds Corners:UIRectCornerTopLeft | UIRectCornerTopRight cornerRadii:CGSizeMake(25, 25)];
    UILabel *titleLbl = [[UILabel alloc] init];
    [whiteView addSubview:titleLbl];
    [titleLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(24);
        make.top.offset(15);
        make.height.offset(30);
    }];
    //TODO: 国际化
    titleLbl.text = @"选择导航";
    titleLbl.font = BFont(20);
    titleLbl.textColor = Black_Color;
    
    UIButton *closeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [whiteView addSubview:closeBtn];
    [closeBtn setImage:[UIImage imageNamed:@"NavBar_Default_Close"] forState:UIControlStateNormal];
    [closeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.offset(-10);
        make.width.height.offset(40);
        make.top.offset(10);
    }];
    [closeBtn addTarget:self action:@selector(hidenAlartView) forControlEvents:UIControlEventTouchUpInside];
    
    UIView *lineView = [UIView setLineViewWithframe:CGRectZero forinView:whiteView];
    [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.offset(0);
        make.height.offset(1);
        make.top.offset(59);
    }];
    UIButton *gdNavcation = [UIButton buttonWithType:UIButtonTypeCustom];
    [gdNavcation setTitle:@"高德地图" forState:UIControlStateNormal];
    [whiteView addSubview:gdNavcation];
    gdNavcation.frame = CGRectMake(0, 58, DEVICE_WIDTH, 60);
    [gdNavcation setTitleColor:Color_333333 forState:UIControlStateNormal];
    
    UIButton *bdNavcation = [UIButton buttonWithType:UIButtonTypeCustom];
    [bdNavcation setTitle:@"百度地图" forState:UIControlStateNormal];
    [whiteView addSubview:bdNavcation];
    bdNavcation.frame = CGRectMake(0, 58 + 60, DEVICE_WIDTH, 60);
    [bdNavcation setTitleColor:Color_333333 forState:UIControlStateNormal];
    [gdNavcation addTarget:self action:@selector(gdNavcation) forControlEvents:UIControlEventTouchUpInside];
    [bdNavcation addTarget:self action:@selector(bdNavcation) forControlEvents:UIControlEventTouchUpInside];

    [UIView setLineViewWithframe:CGRectMake(0, 58 + 60, DEVICE_WIDTH, 1) forinView:whiteView];
    [UIView setLineViewWithframe:CGRectMake(0, 58 + 121, DEVICE_WIDTH, 1) forinView:whiteView];

}

- (void)down:(UILabel *)decLbl{
    WEAKSELF
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        weakSelf.downCont -- ;
        decLbl.text = [NSString stringWithFormat:@"返回首页（%dS）",weakSelf.downCont];
        if(weakSelf.downCont > 0){
            [weakSelf down:decLbl];
        }else{
            [weakSelf hidenAlartView];
            weakSelf.sucessBlock(YES);
        }
    });
}

- (void)showLodingAlertView:(NSString *)title{
    if(_backView){
        [self hidenLodingImageView];
    }
    UIWindow *window = UIApplication.sharedApplication.delegate.window;
    [window addSubview:self.backView];
    _backView.backgroundColor = rgba(0, 0, 0, 0.3);

    _lodingImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"chrysanthemum"]];
    [self.backView addSubview:_lodingImageView];
    [_lodingImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(250 + STATUSBAR_HEIGHT);
        make.width.height.offset(64);
        make.centerX.equalTo(self.backView);
    }];
    UILabel *tipsLbl = [UILabel setLblText:title font:Font(16) withColor:Color_333333 inSubView:self.backView];
    [self.backView addSubview:tipsLbl];
    [tipsLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_lodingImageView.mas_bottom).offset(16);
        make.centerX.equalTo(self.backView);
    }];
    CABasicAnimation *animation =  [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
    //默认是顺时针效果，若将fromValue和toValue的值互换，则为逆时针效果
    animation.fromValue = [NSNumber numberWithFloat:0.f];
    animation.toValue =  [NSNumber numberWithFloat: M_PI *2];
    animation.duration  = 2;
    animation.autoreverses = NO;
    animation.fillMode =kCAFillModeForwards;
    animation.repeatCount = MAXFLOAT; //如果这里想设置成一直自旋转，可以设置为MAXFLOAT，否则设置具体的数值则代表执行多少次
    [_lodingImageView.layer addAnimation:animation forKey:nil];
}

- (void)changsacnImage{
    _currentIndex ++;
    _lodingImageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"loding0%03d",_currentIndex]];
    if(_currentIndex == 135){
        _currentIndex = 62;
    }
}

- (void)gdNavcation{
    //判断是否能打开高德地图
    NSURL * gaode_App = [NSURL URLWithString:@"iosamap://"];
    if ([[UIApplication sharedApplication] canOpenURL:gaode_App]) {
        
        NSString *gdString = [NSString stringWithFormat:@"iosamap://openFeature?featureName=OnRideNavi&rideType=elebike&sourceApplication=appname&lat=%lf&lon=%lf4&dev=0",_latitude,_longitude];
        gdString = [gdString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:gdString] options:@{} completionHandler:nil];
                        //先出现地点位置，然后再手动点击导航
    }else{
        [[KRAlartManager shareInstance] showAlert:@"未下载高德地图APP"];
    }

}

- (void)bdNavcation{
    
    NSURL * baidu_App = [NSURL URLWithString:@"baidumap://"];
    if ([[UIApplication sharedApplication] canOpenURL:baidu_App]) {
        NSString *bdString = [NSString stringWithFormat:@"baidumap://map/direction?origin={{我的位置}}&destination=%f,%f|name:%@",_latitude,_longitude,_pointName];
        bdString = [bdString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:bdString] options:@{} completionHandler:nil];
    }else{
        [[KRAlartManager shareInstance] showAlert:@"未下载百度地图APP"];
    }
}

- (void)showXKAlert{
    
}

- (void)showFirstuseApp{
    [[NSUserDefaults standardUserDefaults] setBool:YES forKey:IS_NOTFIRST_LODINGHOMEVC];
    [[NSUserDefaults standardUserDefaults] synchronize];
    UIWindow *window = UIApplication.sharedApplication.delegate.window;
    [window addSubview:self.backView];
    UIView *whiteView = [[UIView alloc] init];
    whiteView.backgroundColor = Whire_Color;
    [self.backView addSubview:whiteView];
    UILabel *title = [UILabel setLblText:@"温馨提示" font:BFont(20) withColor:Black_Color inSubView:whiteView];
    [title mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(24);
        make.top.offset(16);
        make.height.offset(28);
    }];
    UILabel *decLel = [UILabel setLblText:@"底部导航栏支持上滑拖动或点击页面空白区域显示喔~" font:Font(14) withColor:Black_Color inSubView:whiteView];
    [decLel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(24);
        make.top.equalTo(title.mas_bottom).offset(4);
        make.right.offset(-24);
    }];
    decLel.numberOfLines = 0;
    UIView *lineView = [UIView setLineViewWithframe:CGRectZero forinView:whiteView];
    [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(decLel.mas_bottom).offset(16);
        make.height.offset(1);
        make.left.right.offset(0);
    }];
    UIButton *sureBtn = [UIButton setButtonWithTitle:@"确认" titleColor:Color_7ACC00 titleFont:BFont(16) cornerRadius:0 backColor:Whire_Color];
    [whiteView addSubview:sureBtn];
    [sureBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.offset(0);
        make.top.equalTo(lineView.mas_bottom).offset(0);
        make.height.offset(54);
    }];
    [whiteView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.offset(-84);
        make.left.offset(24);
        make.right.offset(-24);
        make.bottom.equalTo(sureBtn.mas_bottom).offset(0);
    }];
    [whiteView setNeedsLayout];
    [whiteView layoutSubviews];
    whiteView.layer.cornerRadius = 25;
    whiteView.clipsToBounds = YES;
    UIImageView *triangleIcon = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"triangle"]];
    [_backView addSubview:triangleIcon];
    [triangleIcon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(whiteView.mas_bottom).offset(-6);
        make.centerX.equalTo(whiteView);
        make.width.offset(17);
        make.height.offset(12);
    }];
    
    [sureBtn addTarget:self action:@selector(hidenAlartView) forControlEvents:UIControlEventTouchUpInside];
}

- (void)hidenLodingImageView{
    if(_lodingImageView){
        [_lodingImageView.layer removeAllAnimations];
        _lodingImageView = nil;
        [self.backView removeAllSubviews];
        [self.backView removeFromSuperview];
    }
}

-(void)hidenAlartView{
    if(_lodingImageView){
        [_lodingImageView.layer removeAllAnimations];
        _lodingImageView = nil;
    }
    [self.backView removeAllSubviews];
    [self.backView removeFromSuperview];
}
-(UIView *)backView{
    if(!_backView){
        _backView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, DEVICE_WIDTH, DEVICE_HEIGHT)];
        _backView.backgroundColor = rgba(0, 0, 0, 0.3);
    }
    return _backView;
}

- (UIView *)errorView{
    if(!_errorView){
        _errorView = [[UIView alloc] init];
        _errorView.backgroundColor = rgba(0, 0, 0, 0.8);
    }
    return _errorView;
}


@end
